Set-Location $PSScriptRoot

function PackageExists {
  param (
    $package
  )
  (.\Scripts\pip.exe show $package) 1> $null 2> __tmp.log
  $content = Get-Content -Path __tmp.log
  $res = $content.Length -gt 0
  Remove-Item __tmp.log
  return !$res
}
if (Test-Path('.\Scripts\pip.exe')) {
  if (PackageExists('opencv-python')) {
    Write-Output 'it is done'
    return
  }
}

Invoke-WebRequest -Uri "https://bootstrap.pypa.io/get-pip.py" -OutFile "get-pip.py"
.\python.exe get-pip.py -i https://pypi.tuna.tsinghua.edu.cn/simple
.\Scripts\pip.exe install opencv-python numpy pypi-json -i https://pypi.tuna.tsinghua.edu.cn/simple

Remove-Item 'get-pip.py'
